/*
 * edit_party.cc
 * Copyright (C) jurjen 2007 <jurjen@stwerff.xs4all.nl>
 *
 * edit_party.cc is free software. You may redistribute it and/or modify it under
 * the terms of the GNU General Public License.
 */

#define DEBUG_ROUTINE "edit_party"

#include "edit_party.h"
#include "../general/log.h"

edit_party::edit_party(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> refGlade)
: Gtk::Window(cobject), glade(refGlade) {
	edit_party::present();
	glade->get_widget("party_name", party_name);
	glade->get_widget("party_descr", party_descr);
	glade->get_widget("party_cancel", party_cancel);
	glade->get_widget("party_delete", party_delete);
	glade->get_widget("party_ready", party_ready);
	glade->get_widget("party_create", party_create);
	descr_buffer=Gtk::TextBuffer::create();
	party_descr->set_buffer(descr_buffer);

	party_cancel->signal_clicked().connect(sigc::mem_fun(*this, &edit_party::clicked_cancel));
	party_delete->signal_clicked().connect(sigc::mem_fun(*this, &edit_party::clicked_delete));
	party_ready->signal_clicked().connect(sigc::mem_fun(*this, &edit_party::clicked_ready));
}

void edit_party::set_party(party *data, bool isnew, sigc::signal<void> ready) {
    party_name->set_text(data->name);
    descr_buffer->set_text(data->description);
    if (!isnew) {
        party_create->set_label("update");
    }
    party_data=data;
    signal_ready=ready;
}

edit_party::~edit_party() {}

void edit_party::clicked_cancel() {
	hide();
}

void edit_party::clicked_ready() {
    party_data->name=party_name->get_text();
    party_data->description=descr_buffer->get_text();
    signal_ready.emit();
    hide();
}

void edit_party::clicked_delete() {
    party_data->name="";
    party_data->description="";
    signal_ready.emit();
    hide();
}
